unit ColumnsLookup;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DBGridEh, Buttons, Db, DBTables, ExtCtrls, ComCtrls, GridsEh, SchemaDM,commonlib;

type
  TColumnsLoopupUI = class(TForm)
    Panel2: TPanel;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    DBGridEh1: TDBGridEh;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure DBGridEh1DblClick(Sender: TObject);
    procedure DBGridEh1ColWidthsChanged(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    Fschema: TSchemaData;
    procedure OnActivate(var msg: TWMActivate); message WM_ACTIVATE;
  protected
    procedure SetSchema(value: TSchemaData);
    { Private declarations }
  public
    function Execute(HostControl: TWinControl; table_id: integer; var Column_id:
      integer; var Column_Name: string): Boolean;
    property schema: TSchemaData read Fschema write SetSchema;
    { Public declarations }
  end;

var
  ColumnsLoopupUI   : TColumnsLoopupUI;

implementation

{$R *.DFM}

procedure TColumnsLoopupUI.SetSchema(value: TSchemaData);
begin
  FSchema := value;
  dbgrideh1.DataSource := fschema.DataSource_columns3;
end;



function TColumnsLoopupUI.Execute(HostControl: TWinControl; table_id: integer; var
  Column_id: integer; var Column_Name: string): Boolean;
begin
//  if VendorNo <> '' then
//    Table1.Locate('VendorNo',VendorNo,[]);
  schema.ADOQuery_columns3.Close;
  schema.ADOQuery_columns3.Parameters.ParamByName('table_id').Value := table_id;
  schema.ADOQuery_columns3.Open;

  schema.ADOQuery_columns3.Locate('column_id', Column_id, []);

  AdjustDropDownForm(Self, HostControl);
  Visible := True;
  ModalResult := mrCancel;
  while (Visible) do Application.ProcessMessages;
  Result := False;
  if ModalResult = mrOk then
  begin
    Column_id := schema.ADOQuery_columns3.FieldByName('Column_id').AsInteger;
    Column_Name := schema.ADOQuery_columns3.FieldByName('Column_Name').AsString;
    Result := True;
  end;
end;

procedure TColumnsLoopupUI.SpeedButton1Click(Sender: TObject);
begin
  ModalResult := mrOk;
  Close;
end;

procedure TColumnsLoopupUI.SpeedButton2Click(Sender: TObject);
begin
  Close;
end;

procedure TColumnsLoopupUI.DBGridEh1DblClick(Sender: TObject);
begin
  SpeedButton1Click(Sender);
end;

procedure TColumnsLoopupUI.OnActivate(var msg: TWMActivate);
begin
  inherited;
  if (msg.Active = WA_INACTIVE) then
    Close;
end;

procedure TColumnsLoopupUI.DBGridEh1ColWidthsChanged(Sender: TObject);
begin
  ClientWidth := DBGridEh1.Columns[0].Width + DBGridEh1.Columns[1].Width +
    (DBGridEh1.Width - DBGridEh1.ClientWidth) + Panel1.Width + 3;
end;

procedure TColumnsLoopupUI.FormShow(Sender: TObject);
begin
  DBGridEh1ColWidthsChanged(Sender);
end;

end.

